<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    body{
      margin: 0;
      height: 100vh;
      width: 100vw;
      background-color: red;
    }
    .father{
      /* height: 200px; */
      /* width: 200px; */
      background: rgb(161, 129, 129);
    }
    .son{
      width: 200px;
      height: 200px;
      background: rgb(48, 42, 42);
      color: #fff;
      display: inline-block;
      transition: 0.5s;
    }
    .son:hover{
      background-color: red;
    }
    /* a{
      height: 20px;
      width: 20px;
      background: #000;
      border-radius: 50%;
    } */
    .test{
      height: 50px;
      width: 100px;
      background-color: #fff;
      text-align: center;
      line-height: 50px;
    }
  </style>
</head>
<body>
  <div class="father">
    <!-- <a href=""></a> -->
    <div class="son" onclick="throttle">as
      <div class="grandson">
        <a href="">www.baidu.com</a>
      </div>
    </div>
    <div>111</div>
  </div>
  <div class="test">123</div>
</body>

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>

<script>
  
  // window.localStorage.foo = '123';
  // window.localStorage['foo'] = '123';

  // // console.log(window.localStorage.length);
  // // localStorage.removeItem('foo');
  // let a = window.localStorage.getItem('foo')
  // console.log(a);
  // 节流throttle代码（时间戳+定时器）：
// var throttle = function(func, delay) {     
//     var timer = null;     
//     var startTime = Date.now();     
//     return function() {             
//         var curTime = Date.now();             
//         var remaining = delay - (curTime - startTime);             
//         var context = this;             
//         var args = arguments;             
//         clearTimeout(timer);              
//         if (remaining <= 0) {                    
//             func.apply(context, args);                    
//             startTime = Date.now();              
//         } else {                    
//             timer = setTimeout(func, remaining);              
//         }      
//     }
// }
// function handle() {      
//     console.log(Math.random());
// } 
// window.addEventListener('click', throttle(handle, 2000));
// var throttle = function(func, delay) {            
//     var timer = null;            
//     return function() {                
//         var context = this;               
//         var args = arguments;                
//         if (!timer) {                    
//             timer = setTimeout(function() {                        
//                 func.apply(context, args);                        
//                 timer = null;                    
//             }, delay);                
//         }            
//     }        
// }        
// function handle() {            
//     console.log(Math.random());        
// }        
// window.addEventListener('click', throttle(handle, 2000));
// -------------------------------------------------------------------------------------
// axios.all([
//   axios.get('https://jsonplaceholder.typicode.com/posts'),
//   axios.get('https://jsonplaceholder.typicode.com/comments',{params: {postId:1}})

// ]).then(
//   axios.spread((res1,res2) => {
//     console.log(res1);
//     console.log(res2);
//   })
// ).catch(err=>{
//   console.log(err);
// })
// -------------------------------------------------------------------------------------
// var newAxiosRequest = axios.create({
//   baseURL: 'https://jsonplaceholder.typicode.com/',
//   timeout: 2000
// });
// newAxiosRequest({
//   url: 'posts'
// }).then(res=>{
//   console.log(res);
// })
// -------------------------------------------------------------------------------------
axios.interceptors.request.use(config => { //response
  console.log("进入请求拉拦截器");
  return config
},err => {
  console.log("请求失败",err);
})
axios.get('https://jsonplaceholder.typicode.com/comments',{params: {postId:1}}).then(res=>{
  console.log(res);
})
  

</script>
</html>